/**
 * 统一响应结果类
 * 类似SpringBoot的Result
 */
export class Result<T = any> {
    /** 状态码：0-成功，非0-错误 */
    code: number;

    /** 提示信息 */
    msg: string;

    /** 业务数据 */
    data: T;

    constructor(code: number, msg: string, data: T) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /** 成功响应 */
    static ok<T = any>(data: T, msg: string = '操作成功'): Result<T> {
        return new Result(0, msg, data);
    }

    /** 错误响应 */
    static error(msg: string = '操作失败', code: number = 500): Result<null> {
        return new Result(code, msg, null);
    }
}
